package com.sgai.zero_robot;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

import com.sgai.zero_robot.base.BaseApplication;
import com.sgai.zero_robot.core.RobotManagerFactory;
import com.sgai.zero_robot.utils.SPUtils;
/**
 * Describe :
 * Created by zzw on 02 12月 2024
 */
public class App extends Application {
    public static final int TYPE = 3;
    @Override
    public void onCreate() {
        super.onCreate();
        String processName = getProcessName(this);
        if (!getPackageName().equals(processName)) {
            // 非主进程，不初始化
            return;
        }
        APP = this;
        SPUtils.init(this);
        BaseApplication.getInstance().initBaseApplication(this);
    }
    public static Context APP;
    private String getProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : am.getRunningAppProcesses()) {
            if (processInfo.pid == pid) {
                return processInfo.processName;
            }
        }
        return null;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        RobotManagerFactory.getInstance().close();
    }
}
